package cn.hg.jbsa.common.web;

import java.io.Serializable;
import java.util.Collection;

import com.jfinal.plugin.activerecord.Page;

import cn.hg.jboot.core.constant.BaseConstants;
import cn.hutool.core.util.ObjectUtil;

/**
 * @author 胡高
 * @date 2021/11/11
 */
public class LayuiPage implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 448012997404049085L;

    public final static int LAYUI_PAGE_CODE_VALUE_SUCCESSED = 0; 

    protected int code = BaseConstants.RETURN_CODE_VALUE_FAILED;
    protected int count = 0;
    protected String msg = BaseConstants.RETURN_MESSAGE_VALUE_FAILED;

    protected Object data = new Object();

    public LayuiPage () {

    }

    public LayuiPage (Collection<?> list) {
        this.count = ObjectUtil.isNull(list) ? 0 : list.size();
        this.data = list;
        this.code = LAYUI_PAGE_CODE_VALUE_SUCCESSED;
        this.msg = BaseConstants.RETURN_MESSAGE_VALUE_SUCCESSED;
    }

    public LayuiPage (Page<?> page) {
        if (ObjectUtil.isNotNull(page)) {
            this.count = page.getTotalRow();
            this.data = page.getList();
        }
        this.code = LAYUI_PAGE_CODE_VALUE_SUCCESSED;
        this.msg = BaseConstants.RETURN_MESSAGE_VALUE_SUCCESSED;
    }

    public LayuiPage (String errorMessage) {
        this.msg = errorMessage;
    }

    /**
     * @return the code
     */
    public int getCode() {
        return this.code;
    }

    /**
     * @return the count
     */
    public int getCount() {
        return this.count;
    }

    /**
     * @return the data
     */
    public Object getData() {
        return this.data;
    }

    /**
     * @return the msg
     */
    public String getMsg() {
        return this.msg;
    }

    /**
     * @param code the code to set
     */
    public LayuiPage setCode(int code) {
        this.code = code;
        return this;
    }

    /**
     * @param count the count to set
     */
    public LayuiPage setCount(int count) {
        this.count = count;
        return this;
    }

    /**
     * @param data the data to set
     */
    public LayuiPage setData(Object data) {
        this.data = data;
        return this;
    }

    /**
     * @param msg the msg to set
     */
    public LayuiPage setMsg(String msg) {
        this.msg = msg;
        return this;
    }

}
